package com.imooc.cglibproxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
* Created By lijiliang on 2018年7月26日 下午2:32:12
*/
public class CglibProxy implements MethodInterceptor {
	private Enhancer enhancer=new Enhancer();
	public Object getProxy(Class clazz) {
		enhancer.setSuperclass(clazz);
		enhancer.setCallback(this);
		return enhancer.create();
		
		
	}
	
	@Override
	public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		System.out.println("日志开始。。");
		proxy.invokeSuper(obj, args);
		System.out.println("日志结束。。");
		return null;
	}


}
